package com.gitee.wsl.struct.grammar.ast.render.provider


import com.gitee.wsl.struct.grammar.ast.node.ASTNode
import com.gitee.wsl.struct.grammar.ast.node.LeafNode
import com.gitee.wsl.struct.grammar.ast.node.accept
import com.gitee.wsl.struct.grammar.ast.visitor.Visitor

abstract class InlineHolderGeneratingProvider<V: Visitor> : OpenCloseGeneratingProvider<V>() {

    open fun childrenToRender(node: ASTNode): List<ASTNode> {
        return node.children
    }

    override fun processNode(visitor:V, text: String, node: ASTNode) {
        openTag(visitor, text, node)

        for (child in childrenToRender(node)) {
            if (child is LeafNode) {
                visitor.visitLeaf(child)
            } else {
                child.accept(visitor)
            }
        }

        closeTag(visitor, text, node)
    }
}